// 计算两个毫秒时间戳之间的浏览时长，并转换为分秒形式
export function formatViewDuration(startTimeMs, endTimeMs) {
	// 计算相差的毫秒数
	const differenceInMilliseconds = endTimeMs - startTimeMs;

	// 转换为分钟和秒
	const totalSeconds = Math.floor(differenceInMilliseconds / 1000);
	const minutes = Math.floor(totalSeconds / 60);
	const seconds = totalSeconds % 60;

	return `${minutes} 分 ${seconds} 秒`;
}
// 获取当前时间
export function getCurrentTimeFormatted() {
	const now = new Date();
	const hours = now.getHours();
	const minutes = now.getMinutes();
	const seconds = now.getSeconds();

	function padZero(value) {
		return value < 10 ? '0' + value : value;
	}

	const formattedTime = `${padZero(hours)}:${padZero(minutes)}:${padZero(seconds)}`;
	return formattedTime;
}
//并转换为分秒形式
export function calculateTimeDifference(time1, time2) {
	// 将时分秒字符串转换为秒数
	function timeToSeconds(timeStr) {
		const [hours, minutes, seconds] = timeStr.split(':').map(Number);
		return hours * 3600 + minutes * 60 + seconds;
	}

	// 计算秒数差
	const secondsDiff = Math.abs(timeToSeconds(time2) - timeToSeconds(time1));

	// 将秒数差转换为分秒形式
	const minutes = Math.floor(secondsDiff / 60);
	const seconds = secondsDiff % 60;

	// 格式化输出
	return `${padZero(minutes)}分${padZero(seconds)}秒`;

	function padZero(num) {
		return num < 10 ? '0' + num : num;
	}
}